//
//  ZYCTeachLearnStatisticsSliderView.m
//  ZDSC
//
//  Created by ZDTX on 2021/9/12.
//

#import "ZYCTeachLearnStatisticsSliderView.h"
@interface ZYCTeachLearnStatisticsSliderView ()

@property (nonatomic, strong) UILabel *leftLabel;
@property (nonatomic, strong) UILabel *rightLabel;
@property (nonatomic, strong) UIView *slider;
@property (nonatomic, strong) UIView *line;

@end
@implementation ZYCTeachLearnStatisticsSliderView

- (void)setLeftString:(NSString *)leftString{
    _leftString = leftString;
    _leftLabel.text = leftString;
}

- (void)setRightString:(NSString *)rightString{
    _rightString = rightString;
    _rightLabel.text = rightString;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HEX_RGB(@"FFFFFF");
        [self addSubview:self.leftLabel];
        [self addSubview:self.rightLabel];
        [self addSubview:self.slider];
        [self addSubview:self.line];
    
        [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(self.bounds.size.width / 2, self.bounds.size.height));
        }];
        
        [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(self);
            make.right.bottom.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(self.bounds.size.width / 2, self.bounds.size.height));
        }];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self).offset(12.0f);
            make.bottom.equalTo(self).offset(-12.0f);
            make.width.mas_equalTo(1);
        }];
        
        [self.slider mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.leftLabel);
            make.bottom.equalTo(self.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(16, 4));
        }];

        
    }
    return self;
}


- (UILabel *)leftLabel {
    if (!_leftLabel) {
        _leftLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 15.0f) titleColor:HEX_RGB(@"#009043") textAlignment:ZZTextAlignmentCenter];
        _leftLabel.tag = 1000;
        _leftLabel.text = @"已提交";
        _leftLabel.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap:)];
        [_leftLabel addGestureRecognizer:tap];
    }
    return _leftLabel;
}

- (UILabel *)rightLabel {
    if (!_rightLabel) {
        _rightLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 15.0f) titleColor:HEX_RGB(@"#8E8E8E") textAlignment:ZZTextAlignmentCenter];
        _rightLabel.userInteractionEnabled = YES;
        _rightLabel.tag = 1001;
        _rightLabel.text = @"未提交";
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTap:)];
        [_rightLabel addGestureRecognizer:tap];
    }
    return _rightLabel;
}

- (UIView *)slider {
    if (!_slider) {
        _slider = [[UIView alloc] init];
        _slider.backgroundColor = HEX_RGB(@"#009B4C");
        _slider.layer.cornerRadius = 2.0f;
        _slider.layer.masksToBounds = YES;
    }
    return _slider;
}

- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EFEFEF");
    }
    return _line;
}

- (void)clickTap:(UIGestureRecognizer *)tap{
    UILabel* item = (UILabel*)tap.view;
    if (item.tag == 1000) {//已提交
        self.leftLabel.textColor = HEX_RGB(@"#009043");
        self.rightLabel.textColor = HEX_RGB(@"#8E8E8E");
        [UIView animateWithDuration:0.2 animations:^{
            self.slider.transform = CGAffineTransformMakeTranslation(0, 0);
        }];

    }else{//未提交
        self.leftLabel.textColor = HEX_RGB(@"#8E8E8E");
        self.rightLabel.textColor = HEX_RGB(@"#009043");
        [UIView animateWithDuration:0.2 animations:^{
            self.slider.transform = CGAffineTransformMakeTranslation(self.bounds.size.width / 2, 0);
        }];
    }
    
    if (self.selectTitleBlock) {
        self.selectTitleBlock(item.tag);
    }
}

@end
